package com.hanrui.android.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.github.vipulasri.timelineview.TimelineView;
import com.hanrui.android.R;
import com.hanrui.android.model.ThreeSuperviseDetailBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/4/13.
 */

public class ThreeSuperviseLcAdapter extends RecyclerView.Adapter<ThreeSuperviseLcAdapter.LcViewHolder> {
    private List<ThreeSuperviseDetailBean.ThreeColorDetailListBean> mFeedList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public ThreeSuperviseLcAdapter(){

        if (mFeedList == null) {
            mFeedList = new ArrayList<>();
        		}
    }


    public void setNewData(List<ThreeSuperviseDetailBean.ThreeColorDetailListBean> list){
        mFeedList.clear();
        mFeedList.addAll(list);
        notifyDataSetChanged();
    }


    @Override
    public int getItemViewType(int position) {
        return TimelineView.getTimeLineViewType(position,getItemCount());
    }

    @Override
    public LcViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        mLayoutInflater = LayoutInflater.from(mContext);
        View view ;
        view = mLayoutInflater.inflate(R.layout.item_lcthreesupervise,parent,false);
        return new LcViewHolder(view,viewType);
    }

    @Override
    public void onBindViewHolder(LcViewHolder holder, int position) {
        ThreeSuperviseDetailBean.ThreeColorDetailListBean item = mFeedList.get(position);

        holder.mTimelineView.setMarker(ContextCompat.getDrawable(mContext, R.drawable.gouxuan));
        holder.lc_title.setText(item.getOutline());
        holder.lc_content.setText(item.getProgress());
        holder.lc_time.setText(item.getUpdateDate());

    }

    @Override
    public int getItemCount() {
        return mFeedList!=null?mFeedList.size():0;
    }


    class LcViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.lc_title)
        TextView lc_title;
        @BindView(R.id.lc_content)
        TextView lc_content;
        @BindView(R.id.lc_time)
        TextView lc_time;
        @BindView(R.id.time_marker)
        TimelineView mTimelineView;

        public LcViewHolder(View itemView, int viewType) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            mTimelineView.initLine(viewType);
        }
    }
}
